<?php
include('HTGPage.class.php');

$page = new HTGPage();

/* @var $utils Utils */
$utils = $page->myUtils;

$security = $page->mySecurity;

if(!($security->isAdmin())) {
	$page->redirectTo("index.php");
}

if(@$_REQUEST['action'] == 'delete') {
	//deleting the pick
	$tId = $_REQUEST['t_id'];
	$utils->deleteTicker($tId);
}

if(isset($_REQUEST['submit'])) {
	$tickerText = $_REQUEST['tickerText'];
	$tickerURL = $_REQUEST['tickerLink'];
	$expireDate = strftime("%G-%m-%d %H:%M:%S", strtotime($_REQUEST['tickerExpireDate'])); //$_REQUEST['tickerExpireDate'];
	
	$lastId = $utils->addTicker($expireDate, $tickerText, $tickerURL);
	if($lastId > 0) {
		$page->content .= '<h1>Ticker Added</h1>';
	}
}

$page->content .= $utils->get_include_contents('addTickerForm.html');

$page->preHeadCloseContent .= '<link type="text/css" href="addTicker.css" rel="stylesheet" />
<link type="text/css" href="css/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
<script type="text/javascript" src="js/timepicker.js"></script>

 <script type="text/javascript">
 Date.format = \'yyyy-mm-dd\';
$(function() {
    $(\'#tickerExpireDate\').datepicker({
    	duration: \'\',
        showTime: true,
        constrainInput: false
     });
     
});
</script>
';


//todo display tickers with remove button

$page->content .= $utils->returnTickerAdminTable();

$page->display();


?>